﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

public partial class top_reviewnew_buyredirect : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = utils.NewRequest("id", utils.RequestType.QueryString);
        Common.Cookie cookie = new Common.Cookie();
        string taobaoNick = cookie.getCookie("nick");
        string session = cookie.getCookie("top_sessiongroupbuy");
        Rijndael_ encode = new Rijndael_("tetesoft");
        string nick = encode.Decrypt(taobaoNick);

        string sql = "SELECT COUNT(*) FROM TCS_AlipayPayLog WHERE DATEDIFF(d, adddate, GETDATE()) = 0";
        string payCount = utils.ExecuteString(sql);
        string typ = utils.NewRequest("typ", utils.RequestType.QueryString);

        string orderid = DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + (int.Parse(payCount) + 1).ToString();
        string amount = string.Empty;
        string count = string.Empty;

        if (typ == "1")
        {
            count = "100";
            amount = "0.1";
        }
        else if (typ == "2")
        {
            count = "510";
            amount = "45";
        }
        else if (typ == "3")
        {
            count = "1030";
            amount = "85";
        }
        else if (typ == "4")
        {
            count = "5200";
            amount = "400";
        }
        else if (typ == "5")
        {
            count = "10500";
            amount = "750";
        }
        else if (typ == "6")
        {
            count = "50000";
            amount = "3000";
        }
        else
        {
            Response.Write("参数错误！");
            return;
        }

        //先记录在本地数据库
        sql = "INSERT INTO TCS_AlipayPayLog (nick, orderid, typ, amount, count) VALUES ('" + nick + "','" + orderid + "','" + typ + "','" + amount + "','" + count + "')";
        utils.ExecuteNonQuery(sql);

        //跳转
        string url = "http://www.7fshop.com/alipay/msgbuy.aspx?typ=" + typ + "&orderid=" + orderid;
        Response.Redirect(url);
    }
}